<template>
	<view class="score-item">
		<view class="score-item-hd w750 fboxRow Ycenter font24 color-C7C8D4">
			{{type == 2 ? scoreList.gmtModified : scoreList.gmtCreate}}
		</view>
		<view class="score-item-bd fboxCol Ycenter">
			<view class="hd w690 fboxRow Ycenter font24 color-36363A">
				<view class="title fboxRow Ycenter flex1">
					<view class="dot" :class="[type == 1 ? 'bg-00C15D' : type == 2 ? 'bg-3480FF' : 'bg-FFBC44']"></view>
					{{ type == 2 ? '期望成绩': type == 3 ? '高考成绩': scoreList.examName}}
					<view style="margin-left: 16rpx" class="color-9899A1">
						<block v-if="type != 3">(原总分：{{scoreList.totalScore}}分)</block>
						<block v-else>(赋总分：{{scoreList.newTotalScore}}分)</block>
					</view>
				</view>
				<view class="right">
					<view class="color-6A6A6F" v-if="type == 1" data-tag="edit" @tap="pageTo">我的期望 <text
							class="font22 bksCIcon bks-c-ziyuan137bianji-xuanzhong"></text></view>
					<view class="color-6A6A6F" v-if="type == 2" data-tag="edit" @tap="pageTo">编辑 <text
							class="font22 bksCIcon bks-c-ziyuan137bianji-xuanzhong"></text></view>
					<!-- <view class="color-FFBC44" v-if="type == 3" data-tag="yfyd" @tap="pageTo">一分一段表</view> -->
				</view>
			</view>
			<view class="bd w690 fboxWrap">
				<block v-for="(bItem, BIndex) in scoreList.scoreInfos" :key="BIndex">
					<view class="score-tag fboxCol">
						<view class="tit fboxRow Ycenter Xcenter font24 color-9899A1">
							{{bItem.subjectName}}
							<view class="fboxRow Ycenter Xcenter" v-if="bItem.fax">({{type != 3 ? '原' : '赋'}})</view>
						</view>
						<view class="con fboxRow Ycenter Xcenter font24 color-9899A1">
							<text class="fboxRow Ycenter Xcenter color-36363A"
								style="margin-right:20rpx">{{bItem.subjectScore}}</text>分
						</view>
					</view>
				</block>
			</view>
			<view class="ft w690 fboxRow Ycenter font22">
				<view class="time flex1 color-9899A1"><text v-if="type != 3" @tap="delTap"
						class="color-9899A1">删除记录</text></view>
				<view class="right">
					<text v-if="type == 1" style="color:#3480FF" data-tag="fxjpm" @tap="pageTo">赋分排名</text>
					<text style="color:#FFBC44" data-tag="zyfx" data-type="1" @tap="pageTo">分析报告</text>
					<text class="color-00C15D" data-tag="zyfx" data-type="2" @tap="pageTo">推荐院校</text>
				</view>
			</view>
		</view>
		<vip-dialog :showOverlay.sync="showVipDialog" @click="onVipClick" />
	</view>
</template>

<script>
	import {
		myScoreRecordDelete,
		scoreEntering,
		bksScoreAnalysisName,
		isAnalysis
	} from '@/api/bks.volunteer.js'
	import {getBksInfo} from '@/static/js/bks.common.js'
	import VipDialog from '@/pagesBKS/components/vip-dialog.vue'
	export default {
		props: {
			scoreList: {
				type: Object,
				default: () => {
					return {
						// "scoreInfos": [],
						// examName: '三诊成绩',
						// time: '2021.04.28 14:30:20'
					}
				}
			},
			type: {
				type: [String, Number],
				default: 1
			},
			edit: {
				type: Boolean,
				default: true
			},
			studentCode: {
				type: String,
				default: ''
			}
		},
		components: {VipDialog},
		data() {
			return {
				showVipDialog: false,
				tipsCon: '',
				loading: false
			}
		},
		methods: {
			// 删除记录
			delTap(e) {
				console.log('删除')
				uni.showModal({
					title: '提示',
					content: '您确定要删除此记录吗？',
					confirmColor: '#00C15D',
					success: (res) => {
						if (res.confirm) {
							const {
								id,
								studentCode,
								examIdKd
							} = this.scoreList
							const req = {
								id
							}
							if (this.type == 1) {
								req.examId = examIdKd
								req.studentCode = studentCode
							}
							myScoreRecordDelete(req).then(res => {
								if (res.data) {
									uni.showToast({
										title: '删除成功',
										icon: 'none'
									})
									this.$emit('on-delete')
								}
							})
						} else if (res.cancel) {
							console.log('用户点击取消');
						}
					},
					fail: function(res) {

					}
				})
			},
			onVipClick() {
				this.showVipDialog = false
			},
			pageTo(e) {
				const {
					tag,
					code,
					type
				} = e.currentTarget.dataset
				if (tag == 'fxjpm') {
					const {
						scoreList
					} = this
					this.$pageTo('/bks/volunteer/myScore/detail/index', {
						examId: scoreList.examIdKd,
						examName: scoreList.examName,
						examTime: scoreList.examTime,
						studentCode: scoreList.studentCode
					})
				} else if (tag == 'edit') {
					if (this.type == 3) {
						uni.showToast({
							title: '高考成绩，一旦提交不可修改',
							icon: 'none'
						})
					} else {
						this.$emit('on-edit', this.scoreList)
					}
				} else if (tag == 'yfyd') {
					this.$pageTo('/bks/volunteer/myScore/piecewise/index')
				} else if (tag == 'zyfx') {
					if (!this.loading) {
						isAnalysis({
							type: this.type
						}).then(res => {
							if (res.data) {
								this.analysisResults(type)
							} else {
								wx.showToast({
									title: '当前成绩不可分析',
									icon: 'none'
								})
							}
						})
					}
				}
			},
			analysisResults(type) {
				this.loading = true
				// 成绩分析
				getBksInfo('isVip').then(data=>{
					if (data.isVip) {
						// 提示
						bksScoreAnalysisName().then(res => {
							this.tipsCon = res.data
							uni.showModal({
								message: '本次志愿分析，采用的是《' + res.data + '》相关数据进行的智能分析，请知晓。',
								confirmColor: '#00C15D',
								success: (res) => {
									if (res.confirm) {
										scoreEntering({
											id: this.scoreList.id,
											studentCode: '',
											examId: ''
										}).then(res => {
											if (type == 1) {
												this.$pageTo(
													'/bks/volunteer/index/index',
													'switchTab')
											} else {
												this.$pageTo(
													'/bks/volunteer/academy/index/index', {
														activeTab: 0,
														examAnalysisId: res.data.id
													})
											}
										}).complete(err => {
											this.loading = false
										})
									} else if (res.cancel) {
										console.log('用户点击取消');
										this.loading = false
									}
								}
							})

						})
					} else {
						this.loading = false
						this.showVipDialog = true
					}
				})
				console.log(this.showVipDialog)
			}
		}
	}
</script>

<style lang="scss" scoped>
	/* pages/expert/index/expert-item/index.wxss */
	.w690 {
		width: 690rpx;
	}

	.score-item-hd {
		padding: 0 30rpx;
		height: 84rpx;
		border-bottom: 1px solid #EBEBF0;
	}

	.score-item-bd {
		margin: 10rpx 0 30rpx;
		border-bottom: 1px solid #EBEBF0;
	}

	.score-item-bd .hd {
		height: 84rpx;
		border-bottom: 1px solid #EBEBF0;
	}

	.score-item-bd .hd .dot {
		margin-right: 10rpx;
		width: 12rpx;
		height: 12rpx;
		border-radius: 50%;
	}

	.bg-3480FF {
		background-color: #3480FF;
	}

	.bg-FFBC44 {
		background-color: #FFBC44;
	}

	.score-item-bd .bd {
		padding: 20rpx 0;
	}

	.score-item-bd .ft {
		height: 80rpx;
		border-top: 1px solid #EBEBF0;
	}

	.score-item-bd .ft .bksCIcon {
		transform: rotate(0deg);
		transition: transform .3s;
	}

	.score-item-bd .ft .bksCIcon.unfold {
		transform: rotate(180deg);
	}

	.score-item-bd .score-tag {
		padding: 15rpx 0;
		width: 230rpx;
	}

	.score-item-bd .score-tag .con {
		margin-top: 20rpx;
	}

	.right text+text {
		margin-left: 30rpx;
	}

	.plus-class {
		background: none !important;
	}

	.input-class {
		background: none !important;
	}

	.minus-class {
		background: none !important;
	}
</style>